/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2023-10-25 23:08:59
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2023-10-26 11:33:56
 * @FilePath: /three-react/src/geometry/Mash.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import * as THREE from 'three';

export default function createMash() {
  // 创建一个空的几何体顶对象
  const geometry = new THREE.BufferGeometry();
  // 类型化数组定义的一组顶点坐标数据
  const vertices = new Float32Array([
    0, 0, 1, //顶点1法线( 法向量 )
    0, 0, 1, //顶点2法线
    0, 0, 1, //顶点3法线
    0, 0, 1, //顶点4法线
    0, 0, 1, //顶点5法线
    0, 0, 1, //顶点6法线
  ]);
  // BufferAttribute属性缓冲对象表示顶点数据
  const attribute = new THREE.BufferAttribute(vertices, 3);
  // 设置几何体的顶点位置属性
  geometry.attributes.normal = attribute;

  // Uint16Array类型数组创建顶点索引数据
  const indexs = new Uint16Array([0, 1, 2, 0, 2, 3]);
  geometry.index = new THREE.BufferAttribute(indexs, 1);

  // const material = new THREE.MeshBasicMaterial({
  //   color: 0x0000ff, //材质颜色
  //   side: THREE.DoubleSide, //默认只有正面可见
  // });

  const material = new THREE.MeshLambertMaterial({
    color: 0x0000ff,
    side: THREE.DoubleSide, //两面可见
  });

  return new THREE.Mesh(geometry, material);
}

